package com.wlps.aspect;

import com.wlps.result.ResultUtils;
import com.wlps.result.ResultVo;
import com.wlps.result.StatusCode;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Pointcut;

public class CommontResultAspct {
//    @Pointcut("execution("")
    public void pointCut(){}
    @Around("pointCut()")
    public Object doAround(ProceedingJoinPoint proceedingJoinPoint)   {
        ResultVo resultVo;
        Object proceed;
        try{
             proceed = proceedingJoinPoint.proceed();
            resultVo=ResultUtils.success("调用成功", proceed);
        }
        catch (Throwable throwable){
            resultVo = handlerException(throwable);
        }
        return  resultVo;

    }

    public ResultVo handlerException(Throwable throwable){
        return ResultUtils.error(throwable.getMessage());
    }
}
